package com.kiln.juxingqs.ui

import android.content.Intent
import androidx.lifecycle.Observer
import client.global.commlib.dialog.SelectAddrDialog
import client.global.commlib.toast.toast
import com.kiln.juxingqs.BaseMiddleActivity
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GetPpRet
import com.kiln.juxingqs.databinding.ActivityApplythBinding
import com.kiln.juxingqs.ui.vm.ApplyThViewModel


class ApplyThActivity : BaseMiddleActivity<ApplyThViewModel, ActivityApplythBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_applyth
    }

    override fun initView() {
        binding?.apply {
            event = this@ApplyThActivity
            vm = viewModel
            intent.getParcelableExtra<GetPpRet.Deal>("bean")?.let {
                viewModel.bath.value = it
            }
        }
    }

    override fun observerUI() {
        viewModel.forgetRet.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("成功")
                    startActivity(Intent(this@ApplyThActivity, WdthActivity::class.java))
                    finish()
                }
            }
        })
    }

    override fun initViewModel(): ApplyThViewModel = createViewModel()

    fun selectAddr() {
        val dialog = SelectAddrDialog(this)

        var one = ""
        var two = ""
        var three = ""
        dialog.showDialog(one, two, three)
        dialog.onDismis { one, two, three ->
            viewModel.qu.value = "${one.name} ${two.name} ${three.name}"
            viewModel.quIds.value = "${one.id} ${two.id} ${three.id}"
        }
    }
}